#!/usr/bin/env python3
# coding:utf-8
import paho.mqtt.client as mqtt


def on_message(client, userdata, msg):
    print(
        f"Received message: {msg.payload.decode()} on topic {msg.topic} with QoS {msg.qos}")


def on_connect(client, userdata, flags, rc):
    print(f"Connected with result code {rc}")
    client.subscribe("font", qos=1)


def on_disconnect(client, userdata, rc):
    print(f"Disconnected with result code {rc}")


if __name__ == '__main__':
    client = mqtt.Client()
    client.on_connect = on_connect
    client.on_message = on_message
    client.on_disconnect = on_disconnect

    client.connect("127.0.0.1", 1883, 60)
    client.loop_forever()
